package avnf_small.ILP;

/**
 * @author shentianyu
 * @date 2021-01-04 21:49
 */

import java.util.LinkedHashSet;
import java.util.Set;

/**
 * 按照特定的格式生成ILP所需的请求
 */

public class CreateRequest {

    private static int numberOfRequests = 2;
    private static int numberOfVNFNeeded = 2;
    private static int numberOfModLevel = 4;

    private static double basicMod = 12.5;

    private static int numberOfVNFType = 3;

    private static int numberOfThresholdVNF = 15;

    public static void main(String[] args) {

        int[] sourceNode = new int[numberOfRequests];
        int[] destinationNode = new int[numberOfRequests];

        int[][] type = new int[numberOfRequests][numberOfVNFNeeded];

        int[] th = new int[numberOfRequests];

        double[] speed = new double[numberOfRequests];

        int[][] b0 = new int[numberOfRequests][numberOfModLevel];
        int[][] bw = new int[numberOfRequests*2][numberOfModLevel];

        //源节点
        for(int i=0;i<numberOfRequests;i++){
            sourceNode[i] = (int)(Math.random()*6+1);
        }
        //目的节点，和源节点不能重复
        for(int i=0;i<numberOfRequests;i++){
            while(true){
                destinationNode[i] = (int)(Math.random()*6+1);
                if(destinationNode[i]!=sourceNode[i]){
                    break;
                }
            }
        }

        //请求所需的VNF种类，同一个请求中不能有重复
        for(int i=0;i<numberOfRequests;i++){
            Set<Integer> set = new LinkedHashSet<>();
            while(set.size()<numberOfVNFNeeded){
                int vnf = (int)(Math.random()*3+1);
                set.add(vnf);
            }
            int j = 0;
            for(Integer a : set){
                type[i][j] = a;
                j++;
            }
        }

        //延时要求
        for(int i=0;i<numberOfRequests;i++){
            for(int j=0;j<numberOfVNFNeeded;j++){
                th[i]+=(type[i][j]+1)*5*15;
            }
            th[i]+=10;
        }


        //请求的速率[10,100)
        for(int i=0;i<numberOfRequests;i++){
            speed[i] = Math.random()*90+10;
        }

        for(int i=0;i<numberOfRequests;i++){
            for(int j=0;j<numberOfModLevel;j++){
                b0[i][j] = (int)(Math.ceil(speed[i]/((j+1)*1.0*basicMod)));
                bw[i*2][j] = b0[i][j];
                bw[i*2+1][j] = b0[i][j];
            }
        }

        //输出源节点
        System.out.print("s= ");
        for(int i=0;i<numberOfRequests;i++){
            System.out.print(sourceNode[i]+" ");
        }
        System.out.println(";");

        //输出目的节点
        System.out.print("d= ");
        for(int i=0;i<numberOfRequests;i++){
            System.out.print(destinationNode[i]+" ");
        }
        System.out.println(";");
        System.out.println();

        //输出所需的VNF
        System.out.print("type= ");
        for(int i=0;i<numberOfRequests-1;i++){
            for(int j=0;j<numberOfVNFNeeded;j++){
                System.out.print(type[i][j]+" ");
            }
            System.out.println();
            System.out.print("      ");
        }
        for(int j=0;j<numberOfVNFNeeded;j++){
            System.out.print(type[numberOfRequests-1][j]+" ");
        }
        System.out.println(";");
        System.out.println();

        //输出th
        System.out.print("th= ");
        for(int i =0;i<numberOfRequests;i++){
            System.out.print(th[i]+" ");
        }
        System.out.println(";");
        System.out.println();

        //输出b0
        System.out.print("b0= ");
        for(int i=0;i<numberOfRequests-1;i++){
            for(int j=0;j<numberOfModLevel;j++){
                System.out.print(b0[i][j]+" ");
            }
            System.out.println();
            System.out.print("    ");
        }
        for(int j =0;j<numberOfModLevel;j++){
            System.out.print(b0[numberOfRequests-1][j]+" ");
        }
        System.out.println(";");
        System.out.println();

        //输出bw
        System.out.print("bw= ");
        for(int i=0;i<numberOfRequests*2-1;i++){
            for(int j=0;j<numberOfModLevel;j++){
                System.out.print(bw[i][j]+" ");
            }
            System.out.println();
            System.out.print("    ");
        }
        for(int j=0;j<numberOfModLevel;j++){
            System.out.print(bw[numberOfRequests*2-1][j]+" ");
        }
        System.out.println(";");

    }

}
